//
//  DiseaseViewController.m
//  KMedicine
//
//  Created by 452608533 on 16/7/7.
//  Copyright © 2016年 caomu. All rights reserved.
//

#import "DiseaseViewController.h"
#import "WJZDYButton.h"
#import "InessTableViewController.h"
#import "ClassificationOfDiseaseController.h"
#import "FocusDoctorController.h"
#import "CureMethodController.h"
@interface DiseaseViewController ()

@property(nonatomic,weak)UILabel *userLabel;
@property(nonatomic,weak)UILabel *nameLabel;
@property(nonatomic,weak)UILabel *typeLabel;
@property(nonatomic,weak)UILabel *diseseLabel;
@property(nonatomic,weak)WJZDYButton *selDisButton;
@property(nonatomic,weak)WJZDYButton *moreSelButton;
@property(nonatomic,weak)WJZDYButton *yesNoButton;
@property(nonatomic,weak)WJZDYButton *treatButton;
@property(nonatomic,weak)WJZDYButton *patternButton;
@property(nonatomic,weak)UIImageView *DocImage;
@property(nonatomic,weak)UIButton *applyButton;
@property(nonatomic,weak)UILabel *DocLabel;
@property (nonatomic, copy)NSString *name;
@property(nonatomic,weak)UIStackView *stackView;
@end

@implementation DiseaseViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self setupUI];
    
    //自定义返回按钮
    UIButton * backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    backButton.frame = CGRectMake(10, 20, 20, 20);
    [backButton setBackgroundImage:[UIImage imageNamed:@"JianTou"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
    
}

- (void)back{
    //pop到Home界面
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)setupUI {
    
    self.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
    
    //4个label;
    //1.userLabel
    UILabel *userLabel = [[UILabel alloc]init];
    self.userLabel = userLabel;
    userLabel.text = @"用户信息:";
    [userLabel setTextAlignment:NSTextAlignmentCenter];
    NSDictionary *userDict = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:userLabel.text attributes:userDict];
    [userLabel setAttributedText:attr1];
    userLabel.numberOfLines=0;
    [userLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:userLabel];
    
    //2.nameLabel
    UILabel *nameLabel = [[UILabel alloc]init];
    self.nameLabel = nameLabel;
    nameLabel.text = @"王二狗1000099";
    NSDictionary *nameDict = @{NSAttachmentAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr2 = [[NSAttributedString alloc]initWithString:nameLabel.text attributes:nameDict];
    [nameLabel setAttributedText:attr2];
    nameLabel.numberOfLines=0;
    [nameLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:nameLabel];
    
    //3.typeLabel
    UILabel *typeLabel = [[UILabel alloc]init];
    self.typeLabel = typeLabel;
    typeLabel.text = @"疾病类型:";
    NSDictionary *typeDict = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr3 = [[NSAttributedString alloc]initWithString:typeLabel.text attributes:typeDict];
    [typeLabel setAttributedText:attr3];
    typeLabel.numberOfLines = 0;
    [nameLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:typeLabel];
    
    //4.diseseLabel
    UILabel *diseseLabel = [[UILabel alloc]init];
    self.diseseLabel = diseseLabel;
    self.diseseLabel.text = self.title;
    NSDictionary *diseseDict = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr4 = [[NSAttributedString alloc]initWithString:diseseLabel.text attributes:diseseDict];
    [diseseLabel setAttributedText:attr4];
    diseseLabel.numberOfLines = 0;
    [diseseLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:diseseLabel];
    
    //疾病细分
    WJZDYButton *selDisButton = [[WJZDYButton alloc]initWithPlaceHolder:@"请选择疾病细分"];
    
    //选择并发症
    WJZDYButton *moreSelButton = [[WJZDYButton alloc]initWithPlaceHolder:@"请选择并发症(可多选)"];
    
    //是否确诊
    WJZDYButton *yesNoButton = [[WJZDYButton alloc]initWithPlaceHolder:@"是否确诊"];
    
    //是否接受治疗
    WJZDYButton *treatButton = [[WJZDYButton alloc]initWithPlaceHolder:@"是否接受治疗"];
    
    //新增stackView
    UIStackView *stackLayView = [[UIStackView alloc]init];
    self.stackView = stackLayView;
    stackLayView.backgroundColor = [UIColor cyanColor];
    [stackLayView addArrangedSubview:selDisButton];
    [stackLayView addArrangedSubview:moreSelButton];
    [stackLayView addArrangedSubview:yesNoButton];
    [stackLayView addArrangedSubview:treatButton];
    stackLayView.axis = UILayoutConstraintAxisVertical;
    stackLayView.distribution = UIStackViewDistributionFillEqually;
    stackLayView.spacing = 15;
    [self.view addSubview:stackLayView];
    
    //弹窗
    WJZDYButton *patternButton = [[WJZDYButton alloc]initWithPlaceHolder:@"请选择治疗方式"];
    [patternButton setTitle:@"12345678" forState:UIControlStateNormal];
    self.patternButton = patternButton;
    patternButton.frame = CGRectMake(10, 385, 355, 40);
    [self.view addSubview:patternButton];
  
    //block回调
    treatButton.buttonBlock = ^(BOOL status){
        
        if (status) {
            
            patternButton.hidden = YES;
        }else{
            
            patternButton.hidden = NO;
        }
        
    };
    
    //就医生申请button
    UIButton *applyButton = [[UIButton alloc]init];
    self.applyButton = applyButton;
    [applyButton setBackgroundColor:kThemeColor];
    [applyButton setTitle:@"就医生申请" forState:UIControlStateNormal];
    [self.view addSubview:applyButton];
    
    //医生图片image;
    UIImageView *DocImage = [[UIImageView alloc]init];
    self.DocImage = DocImage;
    DocImage.image = [UIImage imageNamed:@"illness_img_person.png"];
    [self.view addSubview:DocImage];
    
    //匹配医生label
    UILabel *DocLabel = [[UILabel alloc]init];
    self.DocLabel = DocLabel;
    DocLabel.text = @"为你匹配到: 42位医生";
    DocLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:DocLabel];
    
    //添加按钮监听
    //疾病细分监听
    [selDisButton addTarget:self action:@selector(didClikSelButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //选择并发症的监听
    [moreSelButton addTarget:self action:@selector(didClikMoreSelButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //就医生申请的监听
    [applyButton addTarget:self action:@selector(applyButtonDidClik:) forControlEvents:UIControlEventTouchUpInside];
    
    [patternButton addTarget:self action:@selector(patternButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //为所有控件添加约束
    [self setConstraint1];
}

//弹窗监听
- (void)patternButtonClick:(WJZDYButton *)sender{
    
    CureMethodController *cuVC = [[CureMethodController alloc] init];
    
    cuVC.methodBlock = ^(NSString *string){
    
        sender.string = string;
      
    };
    
    [self.navigationController pushViewController:cuVC animated:NO];
    
}

//就医生申请的监听
- (void)applyButtonDidClik:(WJZDYButton *)sender{
    
    FocusDoctorController *FDVC = [[FocusDoctorController alloc]init];
    
    [self.navigationController pushViewController:FDVC animated:YES];
    
}

//疾病细分监听
- (void)didClikSelButton:(WJZDYButton *)sender{
    
    ClassificationOfDiseaseController *ClassificationVc = [[ClassificationOfDiseaseController alloc]init];
    ClassificationVc.ClickButtonNumer = self.ClickButtonNumer;
    
    [self.navigationController pushViewController:ClassificationVc animated:YES];
    ClassificationVc.dtoBlock = ^(NSString *name){
        
        sender.string = name;
        
    };
    WJLog(@"选择疾病细分");
}

//选择并发症的监听
- (void)didClikMoreSelButton:(WJZDYButton *)sender{
    
    InessTableViewController *inessTableVC = [[InessTableViewController alloc]init];
    
    inessTableVC.cellBlock = ^(NSString *string){
        
        sender.string = string;
    };
    
    [self.navigationController pushViewController:inessTableVC animated:YES];
    
    WJLog(@"选择并发症");
}

#pragma mark -
#pragma mark -为所有控件添加约束
- (void)setConstraint1{
    
    //userLabel
    [self.userLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_topLayoutGuideBottom).offset(20);
        make.leading.equalTo(self.view).offset(10);
        make.height.equalTo(30);
    }];
    
    //nameLabel
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.userLabel.mas_centerY);
        make.leading.mas_equalTo(self.userLabel.mas_trailing).offset(10);
        make.height.equalTo(30);
    }];
    
    //typeLabel
    [self.typeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.userLabel.mas_bottom).offset(0);
        make.leading.mas_equalTo(self.userLabel.mas_leading).offset(0);
        make.height.equalTo(30);
    }];
    
    //diseseLabel
    [self.diseseLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.typeLabel.mas_centerY);
        make.leading.mas_equalTo(self.typeLabel.mas_trailing).offset(10);
        make.height.equalTo(30);
        
    }];
    
    //就医生申请button
    [self.applyButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(-20);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.height.equalTo(40);
    }];
    
    //    医生图片image
    [self.DocImage makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(80);
        make.width.equalTo(80);
        make.centerX.mas_equalTo(self.applyButton.centerX).offset(0);
        make.bottom.mas_equalTo(self.applyButton.mas_top).offset(-20);
    }];
    
    //匹配医生label
    [self.DocLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.DocImage.mas_top).offset(-20);
        make.leading.equalTo(10);
        make.trailing.equalTo(-10);
        make.height.equalTo(30);
    }];
    
    //stackView
    [self.stackView makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.diseseLabel.mas_bottom).offset(20);
        make.leading.equalTo(10);
        make.trailing.equalTo(-10);
        make.height.equalTo(205);
    }];
    
}

- (void)dealloc {
    
    WJLog(@"控制器挂了");
}

@end














